package kr.hkit.androidcomplete02.ch19;

import kr.hkit.androidcomplete02.R;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.widget.TextView;

public class BackWork extends Activity {
	TextView tv;

	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
		setContentView(R.layout.ch19_backwork);
		tv = (TextView) findViewById(R.id.ch19_backwork_tv);
	}

	public void mOnClick(View v) {
		int start = 0;
		int end = 100;
		int result;
		setProgressBarIndeterminateVisibility(true);
		result = Accumulate(start, end);
		tv.setText("" + result);
		setProgressBarIndeterminateVisibility(false);
	}

	int Accumulate(int start, int end) {
		int sum = 0;
		for (int i = start; i <= end; i++) {
			sum += i;
			try {
				Thread.sleep(20);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}

		return sum;
	}
}
